package com.example.mymatch.controller;

import com.example.mymatch.model.Power;
import com.example.mymatch.service.IPowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制类的实现
 * 编写者：吴茂景
 */
@Api(tags = "权限")
@RestController
public class PowerController {

    @Autowired
    private IPowerService powerService;//对某个业务服务的内容进行定义规范  编写者：吴茂景

    @ApiOperation(value = "查询所有权限信息",notes = "获取权限信息返回json字符串")
    @RequestMapping("/getStr6")
    public String getPower(){
        return "My power";
    }
    @CrossOrigin
    @ApiOperation(value = "对权限信息的添加方法")
    @GetMapping("/addPower")
    public int addPower(Power power){
        System.out.println("进入添加权限信息接口");
        return powerService.insertPower(power);
    }

    @GetMapping("getAll6")
    @ApiOperation(value = "对权限信息的查询方法")
    public List<Power> getAllPower(Power power){
        System.out.println("进入查询方法");

        List<Power> listPower=powerService.getAllPower(power);

        return listPower;
    }

    @PutMapping("/editPower")
    @ApiOperation(value = "对权限信息的修改方法")
    public int EditPower(@RequestBody Power power){
        System.out.println("进入权限修改方法");
        return powerService.updatePower(power);
    }

    @GetMapping("/delPower")
    @ApiOperation(value = "对权限信息的删除方法")
    public int Delete(int powerUserid){
        System.out.println("进入权限删除方法");
        int returnValue=0;
        if (powerUserid!=0){
            Power power=new Power();
            power.setPowerUserid(powerUserid);
            returnValue= powerService.deletePower(power);
        }
        return returnValue;
    }

    @GetMapping("/getOne6")
    @ApiOperation(value = "对单条权限信息的查询方法")
    public Power getPower(int powerUserid){
        Power power=new Power();
        System.out.println("进入单条查询方法");
        if (powerUserid!=0){
            Power power1=new Power();
            power1.setPowerUserid(powerUserid);
            power=powerService.getPower(power1);
            System.out.println("返回的数据集合为："+power.getPowerUserid());
        }
        return power;
    }
}
